package com.anglireports.report.data.chartCommon;

import com.anglireports.report.data.chartCommon.ChartInfo;

import java.util.Comparator;

public class SortComparator implements Comparator<ChartInfo> {
    
    private int sortItem; //1-con 2-emotion 3-vli
    private String sortDire;
    
    public SortComparator(int sortItem, String sortDire) {
        this.sortItem = sortItem;
        this.sortDire = sortDire;
    }
    
    @Override
    public int compare(ChartInfo chartInfo1, ChartInfo chartInfo2) {
        float value1 = 0f;
        float value2 = 0f;
        if(sortItem == 1){
            value1 = chartInfo1.getConcentration();
            value2 = chartInfo2.getConcentration();
        } else if (sortItem == 1){
            value1 = chartInfo1.getEmotion();
            value2 = chartInfo2.getEmotion();
        } else {
            value1 = chartInfo1.getVitality();
            value2 = chartInfo2.getVitality();
        }

        if ("asc".equalsIgnoreCase(this.sortDire)) {
            if(value1 > value2){
                return 1 ;
            } else {
                return -1 ;
            }
        } else if ("desc".equalsIgnoreCase(this.sortDire)) {
            if(value1 > value2){
                return -1 ;
            } else {
                return 1 ;
            }
        } else {
            return 0;
        }

    }
}